package com.example.util;


import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;

@Component
public class WebSocketPusher {

    //给指定的订单发消息
    public void pushToUser(String orderId,String msg){
        WebSocketSession session = MyWebSocketHandler.orderSessionMap.get(orderId);
        if(session !=null && session.isOpen()){
            try{
                session.sendMessage(new TextMessage(msg));
                System.out.println("向订单"+orderId+"发送信息成功");
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }else{
            System.out.println("订单"+orderId+"未连接");
        }
    }







}
